<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{{hostname}}基础监控</title>
  <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/layuimini/css/public.css" media="all">
</head>
<body>
<script src="/static/layui/layui.js"></script>

{% block body %}

<div class="layuimini-container layuimini-page-anim">
        <div class="layuimini-main">
            <form id="asset_form">
            <div class="">
                <div class="">
                    <div class="ibox-title">
                        <h5>图表展示</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>


                    <div class="layui-form-item" style="overflow:scroll;white-space : nowrap">

                            <input name="id" value="{{id}}" type="hidden">

                            <div class="layui-inline"><label class="layui-form-label">{{hostname}}图表监控</label>
                                <div class="col-md-9">
                                    <select class="layui-input-inline" name="slice" id="slice" onchange="change_info()">
                                        {% for type_tuple in time_slice %}
                                            {% if type_tuple.0 == sl  %}
                                                <option value="{{ type_tuple.0 }}" selected="selected"> {{ type_tuple.1 }}</option>
                                            {% else %}
                                                <option value="{{ type_tuple.0 }}"> {{ type_tuple.1 }}</option>
                                            {% endif %}
                                        {% endfor %}
                                    </select>
                                </div>
                            </div>
                    </br>
                    <div class="hr-line-dashed"></div>
                    <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
                    <style type="text/css">
                    .main{float: left;}
                    .main1{float: left;}
                    .main_process{float: left;}
                    .disk{float: left;}
                    </style>
                    {% for ec in ecslist %}
                        <div id="{{ec.1}}" class="{{ec.1}}" style="width:33%;height:350px;"></div>
                    {% endfor %}
                    <div id="disk" class="disk" style="width:33%;height:350px;"></div>
                    {% for ec in nflow_all_list %}
                        <div id="{{ec}}" class="{{ec}}" style="width:33%;height:350px;float: left;"></div>
                    {% endfor %}


                    <script src="https://cdn.bootcss.com/echarts/4.1.0.rc2/echarts-en.common.js"></script>
                    <!--<script src="/static/js/echarts.min.js"></script>-->
                    {% for ec in ecslist %}
                        <script type="text/javascript">
                        // 基于准备好的dom，初始化echarts实例
                        var res = {{ec.0|safe}};
                        //window.alert(res);
                        var myChart = echarts.init(document.getElementById("{{ec.1}}"));
                        var data = [];
                        res.forEach((item)=>{
                            var date = new Date(item.timeline * 1000);
                            var YY = date.getFullYear() + '-';
                            var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                            var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
                            var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
                            var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
                            var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
                            var formatedTime = YY + MM + DD +" "+hh + mm + ss;
                            //var formatedTime = [time.getFullYear(), (time.getMonth()+1 < 10 ? '0'+(time.getMonth()+1) : time.getMonth()+1), time.getDate()].join('-')+' '+[time.getHours(),time.getMinutes(),time.getSeconds()+'0'].join(':');
                            //window.alert(formatedTime);
                            var obj = {name:formatedTime,value: [formatedTime,item.value]};
                            data.push(obj);
                        })
                        //window.alert(data);
                        // 指定图表的配置项和数据
                        var option = {
                            title: {
                                text: "{{ec.2}}"
                            },
                            tooltip: {
                                trigger: 'axis',
                                axisPointer: {
                                    type: 'cross',
                                    label: {
                                        backgroundColor: '#6a7985'
                                    }
                                }
                            },
                            xAxis: {
                                type: 'time',
                                splitLine: {
                                    show: false
                                }
                            },
                            yAxis: {
                                type: 'value',
                                boundaryGap: [0, '100%'],
                                splitLine: {
                                    show: false
                                }
                            },
                            series: [{
                                name: "{{ec.4}}",
                                type: 'line',
                                showSymbol:false,
                                data: data,
                                lineStyle: {
                                            normal: {
                                                    width:0.5//设置线条粗细
                                            }
                                        },
                                areaStyle: {
                                    normal: {
                                        color: {
                                            type: 'linear',//设置线性渐变
                                            x: 0,
                                            y: 0,
                                            x2: 0,
                                            y2: 1,
                                            colorStops: [{
                                                offset: 0, color: "{{ec.3}}" // 0% 处的颜色
                                            }, {
                                                offset: 1, color: 'white' // 100% 处的颜色
                                            }],
                                            globalCoord: false // 缺省为 false
                                        },
                                    }
                                },
                            }],
                        };

                        // 使用刚指定的配置项和数据显示图表。
                        myChart.setOption(option);
                    </script>
                    {% endfor %}

                    <script type="text/javascript">
                        var myChart_commit = echarts.init(document.getElementById("disk"));
                        // 基于准备好的dom，初始化echarts实例
                        var dic = {{disk_root_list|safe}};
                        var dia = {{disk_keys_v|safe}};
                        var dcc = {{color_v|safe}};
                        //console.log(dia);
                         for ( var v in dic ) {
                             window[v] = dic[v];
                             window['data' + v] = [];

                         }


                        for ( var v in dic ) {
                            window[v].forEach((item) => {
                                var date = new Date(item.timeline * 1000);
                                var YY = date.getFullYear() + '-';
                                var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                                var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
                                var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
                                var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
                                var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
                                var formatedTime = YY + MM + DD + " " + hh + mm + ss;
                                var obj = {name: formatedTime, value: [formatedTime, item.value]};
                                window['data' + v].push(obj);
                            })
                        }

                        var template_list = [];
                        var template = {
                                    name: "",
                                    type: 'line',
                                    showSymbol:false,
                                    //color:'green',
                                    data: '',
                                    lineStyle: {
                                                    normal: {
                                                            width:0.1//设置线条粗细
                                                    }
                                                },
                                    areaStyle: {
                                        normal: {
                                            color: {
                                                type: 'linear',//设置线性渐变
                                                x: 0,
                                                y: 0,
                                                x2: 0,
                                                y2: 1,
                                                colorStops: [{
                                                    offset: 0, color: "red" // 0% 处的颜色
                                                }, {
                                                    offset: 1, color: 'white' // 100% 处的颜色
                                                }],
                                                globalCoord: false // 缺省为 false
                                            },
                                        }
                                    },
                                }
                        //console.log(template_list);
                        for ( var v in dic ) {
                            //console.log(v);
                            //console.log(template_list);
                            //var template_use = template;
                            var template_use = JSON.parse(JSON.stringify(template));
                            template_use["data"] = window['data' + v];
                            template_use["name"] = dia[v];
                            //template_use["color"] = dcc[v];
                            template_use['areaStyle']["normal"]["color"]["colorStops"][0]["color"] = dcc[v];
                            template_list.push(template_use);
                        }
                        // 指定图表的配置项和数据
                        var option = {
                            title: {
                                text: "磁盘使用率"
                            },
                            tooltip: {
                                trigger: 'axis',
                                axisPointer: {
                                    type: 'cross',
                                    label: {
                                        backgroundColor: 'rgba(255, 255, 255, .5)'
                                    },
                                    crossStyle: {//线的颜色 axisPointer.type 为 'cross' 时有效。
                                        color: '#fff'
                                    }
                                }
                            },
                            //backgroundColor : 'rgba(43, 62, 75, .5)',//背景颜色
                            toolbox: {//工具栏
                                show: false//是否显示工具栏组件
                            },
                            xAxis: {
                                type: 'time',
                                splitLine: {
                                    show: false
                                }
                            },
                            yAxis: {
                                type: 'value',
                                boundaryGap: [0, '100%'],
                                splitLine: {
                                    show: false
                                },
                                min: 0,
                                max: 100
                            },
                            series: template_list,

                        };

                        // 使用刚指定的配置项和数据显示图表。
                        myChart_commit.setOption(option);
                    </script>



                    <script type="text/javascript">
                    var   nflow_all_list =  {{nflow_all_list|safe}};
                    for (var ec in nflow_all_list) {
                        // 基于准备好的dom，初始化echarts实例
                        var res_innodb_buffer_pool_reads = nflow_all_list[ec]["bytesSent"];
                        console.log(nflow_all_list[ec]["bytesSent"]);

                        var res_Innodb_buffer_pool_pages_flushed = nflow_all_list[ec]["bytesRecv"];
                        console.log(nflow_all_list[ec]["bytesRecv"]);
                        console.log(ec);
                        //window.alert(res);
                        var myChart_nflow = echarts.init(document.getElementById(ec));
                        var data_innodb_buffer_pool_reads = [];
                        var data_Innodb_buffer_pool_pages_flushed = [];

                        res_innodb_buffer_pool_reads.forEach((item) => {
                            var date = new Date(item.timeline * 1000);
                            var YY = date.getFullYear() + '-';
                            var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                            var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
                            var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
                            var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
                            var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
                            var formatedTime = YY + MM + DD + " " + hh + mm + ss;
                            //var formatedTime = [time.getFullYear(), (time.getMonth()+1 < 10 ? '0'+(time.getMonth()+1) : time.getMonth()+1), time.getDate()].join('-')+' '+[time.getHours(),time.getMinutes(),time.getSeconds()+'0'].join(':');
                            //window.alert(formatedTime);
                            var obj = {name: formatedTime, value: [formatedTime, item.value]};
                            data_innodb_buffer_pool_reads.push(obj);
                        })
                        res_Innodb_buffer_pool_pages_flushed.forEach((item) => {
                            var date = new Date(item.timeline * 1000);
                            var YY = date.getFullYear() + '-';
                            var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                            var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
                            var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
                            var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
                            var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
                            var formatedTime = YY + MM + DD + " " + hh + mm + ss;
                            //var formatedTime = [time.getFullYear(), (time.getMonth()+1 < 10 ? '0'+(time.getMonth()+1) : time.getMonth()+1), time.getDate()].join('-')+' '+[time.getHours(),time.getMinutes(),time.getSeconds()+'0'].join(':');
                            //window.alert(formatedTime);
                            var obj = {name: formatedTime, value: [formatedTime, item.value]};
                            data_Innodb_buffer_pool_pages_flushed.push(obj);
                        })

                        //window.alert(data);
                        // 指定图表的配置项和数据
                        var option = {
                            title: {
                                text: ec+"(KB)"
                            },
                            tooltip: {
                                trigger: 'axis',
                                axisPointer: {
                                    type: 'cross',
                                    label: {
                                        backgroundColor: 'rgba(255, 255, 255, .5)'
                                    },
                                    crossStyle: {//线的颜色 axisPointer.type 为 'cross' 时有效。
                                        color: '#fff'
                                    }
                                }
                            },
                            //backgroundColor : 'rgba(43, 62, 75, .5)',//背景颜色
                            toolbox: {//工具栏
                                show: false//是否显示工具栏组件
                            },
                            xAxis: {
                                type: 'time',
                                splitLine: {
                                    show: false
                                }
                            },
                            yAxis: {
                                type: 'value',
                                //boundaryGap: [0, '100%'],
                                splitLine: {
                                    show: false
                                }
                            },
                            grid: {
                                left: 65
                            },
                            series: [{
                                name: "发送数据",
                                type: 'line',
                                showSymbol: false,
                                color: ['#FFA500'],
                                data: data_innodb_buffer_pool_reads,
                                lineStyle: {
                                    normal: {
                                        width: 0.5//设置线条粗细
                                    }
                                },
                                areaStyle: {
                                    normal: {
                                        color: {
                                            type: 'linear',//设置线性渐变
                                            x: 0,
                                            y: 0,
                                            x2: 0,
                                            y2: 1,
                                            colorStops: [{
                                                offset: 0, color: "Orange" // 0% 处的颜色
                                            }, {
                                                offset: 1, color: 'white' // 100% 处的颜色
                                            }],
                                            globalCoord: false // 缺省为 false
                                        },
                                    }
                                },
                            },
                                {
                                    name: "接收数据",
                                    type: 'line',
                                    showSymbol: false,
                                    color: ['#006400'],
                                    data: data_Innodb_buffer_pool_pages_flushed,
                                    lineStyle: {
                                        normal: {
                                            width: 0.5//设置线条粗细
                                        }
                                    },
                                    areaStyle: {
                                        normal: {
                                            color: {
                                                type: 'linear',//设置线性渐变
                                                x: 0,
                                                y: 0,
                                                x2: 0,
                                                y2: 1,
                                                colorStops: [{
                                                    offset: 0, color: "DarkGreen" // 0% 处的颜色
                                                }, {
                                                    offset: 1, color: 'white' // 100% 处的颜色
                                                }],
                                                globalCoord: false // 缺省为 false
                                            },
                                        }
                                    },
                                }],
                        };

                        // 使用刚指定的配置项和数据显示图表。
                        myChart_nflow.setOption(option);

                    }

                </script>

                </div>
                </div>
            </div>
            </form>
        </div>
    </div>
{% endblock %}

{% block load_js %}
    <script src="/static/js/plugins/flot/jquery.flot.js"></script>
    <script src="/static/js/plugins/flot/jquery.flot.tooltip.min.js"></script>
    <script src="/static/js/plugins/flot/jquery.flot.resize.js"></script>
    <script src="/static/layuimini/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>

    <script>
        $(document).ready(function () {
            var d1 = [[1262304000000, 6], [1264982400000, 3057], [1267401600000, 20434], [1270080000000, 31982], [1272672000000,
                26602], [1275350400000, 27826], [1277942400000, 24302], [1280620800000, 24237], [1283299200000, 21004],
                [1285891200000, 12144], [1288569600000, 10577], [1291161600000, 10295]];
            var d2 = [[1262304000000, 5], [1264982400000, 200], [1267401600000, 1605], [1270080000000, 6129], [1272672000000,
                11643], [1275350400000, 19055], [1277942400000, 30062], [1280620800000, 39197], [1283299200000, 37000],
                [1285891200000, 27000], [1288569600000, 21000], [1291161600000, 17000]];

            var data1 = [
                {label: "Data 1", data: d1, color: '#17a084'},
                {label: "Data 2", data: d2, color: '#127e68'}
            ];
            $.plot($("#flot-chart1"), data1, {
                xaxis: {
                    tickDecimals: 0
                },
                series: {
                    lines: {
                        show: true,
                        fill: true,
                        fillColor: {
                            colors: [{
                                opacity: 1
                            }, {
                                opacity: 1
                            }]
                        }
                    },
                    points: {
                        width: 0.1,
                        show: false
                    }
                },
                grid: {
                    show: false,
                    borderWidth: 0
                },
                legend: {
                    show: false
                }
            })
        });

    function timeslice(value) {
            var slice = value.options[value.selectedIndex].value;
                if (slice == ""){
                    return false;
                }
                //window.alert(slice);
                var url = "{% url 'chart_detail' %}?id={{id}}&slice={0}".format(slice);
                this.location.href=url;
            };

    function change_info(){
        var args = $("#asset_form").serialize();
        window.location = "{% url 'chart_detail' %}?" + args
    }

    </script>



{% endblock %}